﻿
using System.Runtime.InteropServices;

namespace UtilPublic;

/// <summary>
/// 
/// </summary>
public static partial class ZCmdArg
{
    //private static readonly string TextLocal = "Development";
    private static readonly string TextPre = "Staging";
    private static readonly string TextProd = "Production";

    /// <summary>
    /// 启动配置
    /// </summary>
    public static CmdOption CmdOptions = new();

    /// <summary>
    /// 游戏
    /// </summary>
    public static ESvGame Game => (ESvGame)CmdOptions.Game;
    /// <summary>
    /// 平台
    /// </summary>
    public static ESvPlatform Plat => (ESvPlatform)CmdOptions.Plat;
    /// <summary>
    /// 服务器环境
    /// </summary>
    public static string Env => CmdOptions.Env;
    /// <summary>
    /// 服务器ID
    /// </summary>
    public static string Id => CmdOptions.Id;
    /// <summary>
    /// 服务器ID
    /// </summary>
    public static int IdInt => Id.ToInt();
    /// <summary>
    /// 开发环境
    /// </summary>
    public static bool IsLocal;
    /// <summary>
    /// 测试环境
    /// </summary>
    public static bool IsPre;
    /// <summary>
    /// 生产环境
    /// </summary>
    public static bool IsProd;

    /// <summary>
    /// 
    /// </summary>
    /// <param name="args"></param>
    /// <exception cref="Exception"></exception>
    public static void ParseArgs(string[] args)
    {
        var stringargs = string.Join(" ", args);
        Util.Show($"使用程序 命令行参数 {stringargs}");
        // 命令行参数
        CmdOptions = Parser.Default.ParseArguments<CmdOption>(args)
            .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
            .Value;

        IsPre = CmdOptions.Env == TextPre;
        IsProd = CmdOptions.Env == TextProd;
        IsLocal = (!IsPre && !IsProd);

        Util.Show($"ZCmdArg.ParseArgs IsLocal:{IsLocal} IsPre:{IsPre} IsProd:{IsProd}");
    }
}

/// <summary>
/// 
/// </summary>
public class CmdOption
{
    /// <summary>
    /// 游戏
    /// </summary>
    [Option("game", Required = false, Default = 0)]
    public int Game { get; set; } = 0;
    /// <summary>
    /// 平台
    /// </summary>
    [Option("platform", Required = false, Default = 0)]
    public int Plat { get; set; } = 0;
    /// <summary>
    /// 服务器环境
    /// </summary>
    [Option("environment", Required = false, Default = "Development")]
    public string Env { get; set; } = "";
    /// <summary>
    /// 服务器ID
    /// </summary>
    [Option("id", Required = false, Default = "")]
    public string Id { get; set; } = "";
}

/// <summary>
/// 游戏
/// </summary>
public enum ESvGame
{
    /// <summary>
    /// 梦幻合合合
    /// </summary>
    Mhhhh = 0,
    /// <summary>
    /// 美食奇遇记
    /// </summary>
    Msqyj = 1,
    /// <summary>
    /// 森林环游记
    /// </summary>
    Slhyj = 2,
}

/// <summary>
/// 平台渠道
/// </summary>
public enum ESvPlatform
{
    /// <summary>
    /// 默认的
    /// </summary>
    Default = 0,
    /// <summary>
    /// 微信
    /// </summary>
    Wx = 1,
    /// <summary>
    /// 支付宝
    /// </summary>
    Zfb = 2,
    /// <summary>
    /// 抖音
    /// </summary>
    Dy = 3,
    /// <summary>
    /// APP
    /// </summary>
    App = 4,
}